<?php
/**
 * 轻云网络验证系统
 * =======================================================
 * 版权所有(C) 2019-2039 daenx.cn，并保留所有权利。
 * 作者：Daen大恩
 * 作者QQ: 1330166565
 * 开发群：661059773
 * =======================================================
 */


//判断是否已安装
if(!is_file("./install/lock") && is_file("./install/index.php")){
	@header("location:install/index.php");
}
include 'data/weby.php';
?>
<?php
include 'head.php';
?>
      <div class="lyear-layout-sidebar-scroll"> 
        
        <nav class="sidebar-main">
          <ul class="nav nav-drawer">
            <li class="nav-item"> 
            <a href="index.php">
            <i class="mdi mdi-home"></i> 首页</a> 
            </li>
            <li class="nav-item"> 
            <a href="dlqq.php">
            <i class="mdi mdi-account"></i> 代理查询</a> 
            </li>
            <li class="nav-item active"> 
            <a href="buy.php">
            <i class="mdi mdi-arrow-down-bold"></i> 自助授权</a> 
            </li>
            <li class="nav-item"> 
            <a href="change.php">
            <i class="mdi mdi-account-settings-variant"></i> 更换授权</a> 
            </li>
			<li class="nav-item"> 
            <a href="javascript:void(0)" onclick="dail()">
            <i class="mdi mdi-account-box"></i> 购买授权</a> 
            </li>
          </ul>
        </nav>
        
        <div class="sidebar-footer">
          <p class="copyright">Copyright &copy; 2020. <a target="_blank" href="http://wpa.qq.com/msgrd?v=3&amp;uin=<?php echo $kfqq; ?>&amp;site=qq&amp;menu=yes"><?php echo $kfname; ?></a></p>
        </div>
      </div>
      
    </aside>
    <!--End 左侧导航-->
    
    <!--头部信息-->
    <header class="lyear-layout-header">
      
      <nav class="navbar navbar-default">
        <div class="topbar">
          
          <div class="topbar-left">
            <div class="lyear-aside-toggler">
              <span class="lyear-toggler-bar"></span>
              <span class="lyear-toggler-bar"></span>
              <span class="lyear-toggler-bar"></span>
            </div>
            <span class="navbar-page-title"> <?php echo $title;?> </span>
          </div>
          
          <ul class="topbar-right">
            <li class="dropdown dropdown-profile">
              <a href="javascript:void(0)" data-toggle="dropdown">
                <span>联系我们 <span class="caret"></span></span>
              </a>
              <ul class="dropdown-menu dropdown-menu-right">
                <li> <a href="http://wpa.qq.com/msgrd?v=3&amp;uin=<?php echo $kfqq; ?>&amp;site=qq&amp;menu=yes"><i class="mdi mdi-delete"></i> 联系作者</a></li>
                <li class="divider"></li>
                <li> <a href="http://wpa.qq.com/msgrd?v=3&amp;uin=<?php echo $kfqq; ?>&amp;site=qq&amp;menu=yes"><i class="mdi mdi-comment-outline"></i> 联系客服</a> </li>
              </ul>
            </li>
    
          </ul>
          
        </div>
      </nav>
      
    </header>
    <!--End 头部信息-->
<main class="lyear-layout-content">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<div class="card">
<ul class="nav nav-tabs page-tabs">
<li class="active"> <a href="#!">自助授权</a> </li>

</ul>
<form action="?" method="get">
<div class="tab-content">
<div class="tab-pane active">
<div>

<div class="form-group">
<label for="web_site_title">卡密</label>
<input type="text" id="km" name="km" class="form-control" lay-verType="tips" placeholder="请输入卡密" required/>
</div>
<div class="form-group">
<label for="web_site_title">机器人QQ</label>
<input type="text" id="domain" name="domain" class="form-control" lay-verType="tips" placeholder="请输入机器人QQ" required/>
</div>
<div class="form-group">
<label for="web_site_title">主人QQ</label>
<input type="text" id="qq" name="qq" class="form-control" lay-verType="tips" placeholder="请输入主人QQ" required/>
</div>
<hr/>
<button type="submit" onclick="check()" class="btn btn-primary btn-block">点击查询</button>
<?php
//include 'data/config.php';
$username=$_GET["username"];
$domain=$_GET["domain"];
$qq=$_GET["qq"];
$km=$_GET["km"];
$nowtime=time();
$pass=$_GET["pass"];

if($qq){
	if($domain==""){
		header('Content-type:text/html;charset=utf-8');
		echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">机器人QQ不能为空!</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'buy.php' });  }});</script>");
	}else{
		header('Content-type:text/html;charset=utf-8');
		if($km==""){
			header('Content-type:text/html;charset=utf-8');
			echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">卡密不能为空!</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'buy.php' });  }});</script>");
		}else{
			if($km=="admin"){
				header('Content-type:text/html;charset=utf-8');
				echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">卡密有误或无法使用!</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'buy.php' });  }});</script>");
			}else{
			$sql="SELECT * FROM `cami` where km='$km' limit 1";//判断卡密
			$row=mysqli_fetch_array(mysqli_query($con,$sql));
			if($row){
				
				//添加授权
				$yme=$row['ytime'];
				$cp=$row['cp'];		
				$kmid=$row[id];
				$up=$row['up'];
				
				mysqli_select_db($dbname);
				mysqli_query($con,"set names utf8");
				$sql="select * from authorize where domain='$domain' and ycp='$cp'";
				$query=mysqli_query($con,$sql);
				$rows = mysqli_num_rows($query);
				$row=mysqli_fetch_assoc($query);
				
				
					mysqli_query($con,"DELETE FROM `cami` where `id` = $kmid ");//删除卡密
					$status = '已使用';
					$status = base64_encode($status);
					$sql = "INSERT INTO `camilog` (`domain`, `km`, `time`,  `status`,  `ytime`,`cp`) VALUES ('$domain', '$km', '$nowtime', '$status', '$yme','$cp');";
					mysqli_query($con,$sql);
					
					
				if($rows > 0){
					$zhurenqq = $row['qq'];
					if($row['time']=="free")
					{
						if($yme == '+100year')
						{$time = '';}
					else
						{$time = strtotime($yme);}
					}
					else
					{
						if($yme == '+100year')
						{$time = '';}
					else
						{$time = strtotime($yme,$row['time']);}
						
					}
					$sql = "UPDATE `authorize` SET `time` = '$time' WHERE domain='$domain' and ycp='$cp';";
					mysqli_query($con,$sql); 
					}else{
					$zhurenqq = $qq;
					if($yme == '+100year')
						{$time = '';}
					else
						{$time = strtotime($yme);}
					$sql = "INSERT INTO `authorize` (`username`,`domain`,`pass`,  `qq`,  `time`, `syskey`, `ycp`, `dl`, `up`) VALUES ('$domain','$domain','$km','$zhurenqq',  '$time', '$km', '$cp', '普通用户', '$up');";//添加授权
					mysqli_query($con,$sql); 
					
				}
				if($time == null){$dsc="永久";}
				else{$dsc=date("Y-m-d",$time);}
				header('Content-type:text/html;charset=utf-8');
				echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '280px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">授权成功<br>机器人QQ：".$domain."<br>主人QQ：".$zhurenqq."<br>产品：".$cp."<br>到期日期：".$dsc."</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'buy.php' });  }});</script>");
					
					
				}else{
					
				$sql="SELECT * FROM `cami_ye` where km='$km' limit 1";//判断卡密
				$row=mysqli_fetch_array(mysqli_query($con,$sql));
				if($row){
				//添加授权
				$ye=$row['ye'];
				$cp=$row['cp'];		
				$kmid=$row[id];
				$up=$row['up'];
				
				mysqli_select_db($dbname);
				mysqli_query($con,"set names utf8");
				$sql="select * from authorize where domain='$domain' and ycp='$cp'";
				$query=mysqli_query($con,$sql);
				$rows = mysqli_num_rows($query);
				$row=mysqli_fetch_assoc($query);
				
				mysqli_query($con,"DELETE FROM `cami_ye` where `id` = $kmid ");//删除卡密
					$status = '已使用';
					$status = base64_encode($status);
					$sql = "INSERT INTO `camilog` (`domain`, `km`, `time`,  `status`,  `ytime`,`cp`) VALUES ('$domain', '$km', '$nowtime', '$status', '$ye','$cp');";
					mysqli_query($con,$sql);
					
					$ip = getip();
					
					
				if($rows > 0){
					$zhurenqq = $row['qq'];
					$zye = $row['rmb'] + $ye;
					$sql = "INSERT INTO `log_rmb` (`domain`,`time`,`cp`,`rmb`,`zrmb`,`bz`,`ip`) VALUES ('$domain', '$nowtime', '$cp', '+$ye', '$zye', '网页使用-余额卡密','$ip');";//添加流水日志
					mysqli_query($con,$sql);
					$sql = "UPDATE `authorize` SET `rmb` = '$zye' WHERE domain='$domain' and ycp='$cp';";
					mysqli_query($con,$sql); 
			}else{
					$zhurenqq = $qq;
					$zye = $ye;
					$sql = "INSERT INTO `log_rmb` (`domain`,`time`,`cp`,`rmb`,`zrmb`,`bz`,`ip`) VALUES ('$domain', '$nowtime', '$cp', '+$ye', '$zye', '网页使用-余额卡密','$ip');";//添加流水日志
					mysqli_query($con,$sql);
					$sql = "INSERT INTO `authorize` (`username`,`domain`,`pass`,  `qq`,  `time`, `syskey`, `ycp`, `dl`, `rmb`, `up`) VALUES ('$domain','$domain','$km','$zhurenqq',  'free', '$km', '$cp', '普通用户','$zye','$up');";//添加授权
					mysqli_query($con,$sql); 
				}
				
					header('Content-type:text/html;charset=utf-8');
					echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '280px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">充值成功<br>机器人QQ：".$domain."<br>主人QQ：".$zhurenqq."<br>产品：".$cp."<br>现有余额：".$zye."</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'buy.php' });  }});</script>");
					mysqli_close();
					
				}else{
					header('Content-type:text/html;charset=utf-8');
					echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">卡密错误或者已被使用!</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'buy.php' });  }});</script>");
				}
			}
		}
	}
}}
?>	
<hr/>
</div>
</div>    
</div>
</div>
</form>


<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-header">
<h4>说明</h4>
</div>
<div class="card-body">
</p>
1、此处可以激活新授权、也可以续费授权</p>
2、此处可以自动识别卡密类别，请放心使用</p>
</div>
</div>
</div>
<script src="/assets/layui.js"></script>
<script type="text/javascript" src="./assets/js/jquery.min.js"></script>
<script type="text/javascript" src="./assets/js/bootstrap.min.js"></script>
<script type="text/javascript" src="./assets/js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="./assets/js/main.min.js"></script>
</body>
</html>